package lol.clann.minecraft.springboot.plugin.core;

import com.google.auto.service.AutoService;
import lol.clann.minecraft.springboot.api.model.core.Plugin;
import lol.clann.minecraft.springboot.api.spi.sbp.ApplicationRunListener;
import lol.clann.minecraft.springboot.api.context.PluginContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 启动失败时,保存已经读取到的配置
 *
 * @author pyz
 * @date 2019/6/24 2:02 PM
 */
@Slf4j
@AutoService(ApplicationRunListener.class)
public class StartFailListener implements ApplicationRunListener {
    @Override
    public void failed(SpringApplication application, ConfigurableApplicationContext context, Throwable exception) {
        LOGGER.warn("检测到SpringBootPluginq启动失败,保存已读取的配置");
        for (Plugin plugin : PluginContext.getPlugins()) {
            plugin.saveConfig();
        }
    }
}
